package com.yanqu.road.server.cmd.tradewar.cross;

import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.cross.tradewar.CrossTradeWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.TradeWarActivityMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_CROSS_TRADE_WAR_WANTED_DETAIL, desc = "跨服商战通缉详情")
public class CrossTradeWarWantedDetailCmd extends AbstractCommand {
	private int activityId;
	private String wantedUid;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		CrossTradeWarProto.CrossTradeWarWantedDetailReqMsg reqMsg = CrossTradeWarProto.CrossTradeWarWantedDetailReqMsg.parseFrom(packet.getBytes());
		activityId = reqMsg.getActivityId();
		wantedUid = reqMsg.getWantedUid();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		if(!TradeWarActivityMgr.canCrossTradeWar(activityId, player.getUserId())){
			ret = GameErrorCode.E_CROSS_TRADE_WAR_ACTIVITY_NO_QUALIFIED;
		}
		//到跨服获取详情
		CrossTradeWarProto.CrossTradeWarWantedDetailReqMsg.Builder msg = CrossTradeWarProto.CrossTradeWarWantedDetailReqMsg.newBuilder();
		msg.setActivityId(activityId);
		msg.setWantedUid(wantedUid);
		player.sendUnionActivityGroupPacket(CrossProtocol.C_CROSS_TRADE_WAR_WANTED_DETAIL, msg, activityId);
	}

	@Override
	public void sendData(GamePlayer player) {
		if(0 != ret) {
			CrossTradeWarProto.CrossTradeWarWantedDetailRespMsg.Builder respMsg = CrossTradeWarProto.CrossTradeWarWantedDetailRespMsg.newBuilder();
			respMsg.setRet(ret);
			player.sendPacket(Protocol.U_CROSS_TRADE_WAR_WANTED_DETAIL, respMsg);
		}
	}
}
